//
//  UIView+CXView.m
//  医讯通
//
//  Created by Cynic on 2018/6/15.
//  Copyright © 2018年 Cynic. All rights reserved.
//

#import "UIView+CXView.h"

@implementation UIView (CXView)

-(void)setLayerwid:(CGFloat)wid withColor:(UIColor *)color withRadius:(CGFloat)radius{
    self.layer.borderWidth = wid;
    self.layer.borderColor = color.CGColor;
    self.layer.cornerRadius = radius;
}


-(void)loadLayerViewBaseView:(UIView *)SuperView withHit:(CGFloat)layerHit withDistype:(NSInteger)disType withColor:(UIColor *)layerColr{
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectZero];
    bottomView.backgroundColor = [UIColor lightGrayColor];
    [SuperView addSubview:bottomView];
    bottomView.backgroundColor = layerColr;
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        if(disType % 2 ==0){
            if (disType == 0) {
                make.left.right.top.mas_equalTo(0);
            } else {
                make.left.right.bottom.mas_equalTo(0);
            }
            //        make.left.right.bottom.mas_equalTo(0);
            make.height.mas_equalTo(layerHit);
        }
        else{
            if (disType == 1) {
                make.top.bottom.right.mas_equalTo(0);
            } else {
                make.top.bottom.left.mas_equalTo(0);
            }
            make.width.mas_equalTo(layerHit);
        }
    }];
}

- ( id)tableView{
    if ([self isKindOfClass:[UITableViewCell class]]) {
        UIView*tableView =self.superview;
        
        while(![tableView isKindOfClass:[UITableView class]] && tableView) {
            
            tableView = tableView.superview;
            
        }
        return(UITableView*)tableView;
    }
    return @"";
}



#pragma mark--渐变layer添加 已默认颜色变化值 记得bringtofront 控件
-(void)AddColorsFrom:(UIColor *)fromColor ToEndColor:(UIColor *)endColor{
    CAGradientLayer *layer = [CAGradientLayer layer];
    layer.frame = self.bounds;
    layer.colors = @[(id)[CXSinglerModel colorWithHex:@"#FF7F5A" alpha:1].CGColor,(id)[CXSinglerModel colorWithHex:@"#FE4438" alpha:1].CGColor];
    layer.startPoint = CGPointMake(0, 0);
    layer.endPoint = CGPointMake(1, 0);
    [self.layer addSublayer:layer];
}
@end
